package com.fc.backingbeans.food;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fc.entities.Food;
import com.fc.services.FoodService;

/**
 * 
 * @author �cs �d�m
 * 
 */
@Component("foodTableController")
@Scope("session")
public class FoodTableController implements Serializable {
	@Autowired
	private FoodService foodService;

	private SelectItem[] nameOptions;

	private List<Food> filtered;
	private List<Food> foods;

	public FoodTableController() {
		super();
	}

	private SelectItem[] createFilterOptions(String[] data) {
		SelectItem[] options = new SelectItem[data.length + 1];

		options[0] = new SelectItem("", "Select");
		for (int i = 0; i < data.length; i++) {
			options[i + 1] = new SelectItem(data[i], data[i]);
		}

		return options;
	}

	public List<Food> getFiltered() {
		return filtered;
	}

	public void setFiltered(List<Food> filtered) {
		this.filtered = filtered;
	}

	public List<Food> getFoods() {
		if (foods == null) {
			foods = foodService.findAll();
		}
		
		return foods;
	}
}
